#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

#include <time.h>
#include "Solutions.h"

bool comp_p(Solution *s1, Solution *s2) {
	return (s1->getSignal() > s2->getSignal());
}
bool comp(Solution s1, Solution s2) {
	return (s1.getSignal() > s2.getSignal());
}

int main()
{
	/// CREATION GENERATION DE BASE ///
	srand(time(NULL));
	Solution sol[10];
	for(unsigned int i = 0; i < 10; i++)
	{
		for(unsigned int j = 0; j < 10; j++)
		{
			sol[i].setComb(rand()%2, j);
		}
	}
	// // 

	bool runing = true;
	int gen = 1;
	std::vector<Solution> currentSol;
	while(runing)
	{
		std::cout << " ---- GENERATION " << gen << " ----" << std::endl;		
		//// CLASSEMENT DES INDIVIDUS ////
		std::vector<Solution> vec_sol;
		if(gen = 1)
		{		
			for(unsigned int i = 0; i<10; i++)
			{ 
				vec_sol.push_back(*(new Solution(sol[i])));
			}
		}
		else
			vec_sol = currentSol;

		std::sort(vec_sol.begin(), vec_sol.end(), comp);
		
		for(unsigned int i = 0; i < 10; i++)
		{
			std::cout << i << " : " << vec_sol[i].getSignal() << std::endl;
			
			std::cout << " -> Combinaison ( ";
			for(unsigned int j = 0; j<10; j++)
				std::cout << vec_sol[i].getComb(j) << " ; ";				
		}
		std::cout << std::endl;
		system("PAUSE");
		// //

		//// SELECTION ELITISTE /////
		std::vector<Solution> newgen;
		for(unsigned int i = 0; i < 4; i++) //// SELECTION DES 4 MEILLEURS
		{
			newgen.push_back(vec_sol[i]);
		}		 
		// //

		//// CROISEMENTS ////
		for(unsigned int l = 0; l<6; l++)
		{
			Solution newInv;
			int k = rand()%4;
			for(unsigned int i = 0; i < 5; i++)
				newInv.setComb(newgen[k].getComb(i), i);
		
			k = rand()%4;
			for(unsigned int i = 5; i < 10; i++)
				newInv.setComb(newgen[k].getComb(i), i);

			newgen.push_back(*(new Solution(newInv)));
		}

		currentSol = newgen;
		gen++;

	}
	
	system("PAUSE");	




	return EXIT_SUCCESS;
}